package upload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * @author annvcit
 * @full_name Nguyen Van Chuc An
 * @email annvcit@gmail.com
 * @date_created Dec 24, 2014
 *
 */


public final class Uploader {
	
	private static final String UPLOAD_FOLDER = "/home/annvcit/Desktop/clientupload_folder/";
	
	public static final void upload(String clientFilePath) {
		try {
			File clientFile = new File(clientFilePath);
			BufferedInputStream bis = new BufferedInputStream(
										new FileInputStream(clientFilePath));
			BufferedOutputStream bos = new BufferedOutputStream(
										new FileOutputStream(UPLOAD_FOLDER + clientFile.getName()));
			
			byte[] buffer = new byte[1024];
			int byteRead;
			
			while ((byteRead = bis.read(buffer)) != -1) {
				bos.write(buffer, 0, byteRead);
			}
			bis.close();
			bos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
